<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../lib/vue.js"></script>
    <script src="../lib/vue-router.js"></script>
    <link rel="stylesheet" href="../lib/animate.css">
    <style>
        .box{
            width: 170px;
            height: 170px;
            background-color: aquamarine;
            border: 1px solid #999;
        }
    </style>
</head>

<body>
    <div id="app">
        <h2>{{title}}</h2>
        <myhead></myhead>
        <!-- 定义的路由显示 -->
        <router-view class="box"></router-view>
        <hr>
        <router-link to="/home">首页</router-link>
        <router-link to="/find">发现</router-link>
        <router-link to="/mine">我的</router-link>
        <router-link to="/aboutus">关于我们</router-link>
        <router-link to="/404">报错</router-link>
        <!-- 后面添加就定义路由组件 ，定义路由的path 显示数据 -->
    </div>

    <!-- 定义路由组件部分 -->
    <template id="home">
        <h2>
            Home = home - home
        </h2>
    </template>
    <template id="mine">
        <div>
            Mine  - mine  - 个人中心
        </div>
    </template>
    <template id="aboutus">
        <div>
            aboutus - Aboutus--关于我们
        </div>
    </template>
    <script>
        Vue.component('myhead', {
            template: "<h2>Head - wh2114 - daydayup</h2>"
        })
        //如果不在tenplate里面写的话可以在修改数据里面写样式
        // 1.定义路由组件
        const Home = {
            template: "#home"
        }
        const Find = {
            template: "<h2>Find - find - find</h2>"
        }
        const Mine = {
            template: "#mine"
        }
        const NotFound = {
            template:"<h2> 404 - 4004</h2>"
        }
        const Aboutus = {
            template:'#aboutus'
        }
        // 2.定义路由
        //显示路径   然后是component对应的template展示数据
        const routes = [
            { path: '/home', component: Home },
            { path: '/find', component: Find },
            { path: '/mine', component: Mine },
            { path:'/404',component:NotFound},
            {path:'/aboutus',component:Aboutus}
        ]
        // 3.创建路由实例并传递
        const router = new VueRouter({
            routes: routes
        })
        // 4.路由挂载到根实例
        const vm = new Vue({
            router,//this.$router是内置的实例方法属性
            data: {
                title: "Vue 路由初步",
            },
            components: {
                //局部变量
            },
            watch: {
                '$route': function (to, from) {
                    console.log(to);
                    console.log(from);
                }
            },
            mounted() {
                document.getElementsByTagName("title")[0].innerHTML = this.title;
                console.log(this.$router) // 路由对象
                console.log(this.$route)   //  路由信息对象
            },
        }).$mount("#app")
    </script>
</body>

</html>